<template>
    <div>
        <div class="main" ref="main"></div>
    </div>
</template>

<script>
    import * as echarts from "echarts";

    export default {
        name: "EventView",
        data (){
            return {
                myChart : null,
               option: {
                    xAxis: {
                        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
                    },
                    yAxis: {},
                    series: [
                        {
                            name: '销量',
                            type: 'bar',
                            data: [5, 20, 36, 10, 10, 20]
                        }
                    ]
                }
            }
        },
        mounted(){
            this.myChart = echarts.init(this.$refs.main)
            this.myChart.setOption(this.option)

            //给echarts图表绑定事件
            this.myChart.on("click", function (params) {
                console.log(params, params.name, params.data);  // 正常输出内容
                // console.log(encodeURIComponent(params.name), params.data); // 转换成URL编码
            })

        }
    }
</script>

<style scoped>
    .main {
        width: 60vw;
        height: 550px;
        box-shadow: 1px 1px 10px #333;
        margin: 20px auto;
    }
</style>